package com.itheima.tliassystem.controller;


import com.itheima.tliassystem.aspect.EmpLoginLog;
import com.itheima.tliassystem.service.EmpService;

import entity.Emp;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.tliassystem.uile.JwtUtils;

import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginCobtroller {
    @Autowired
    EmpService empService;
    //登录
    @PostMapping("/login")
    @EmpLoginLog
    public Result login(@RequestBody Emp emp){
        Emp emp1 = empService.checkLongin(emp);
        if (emp1 == null) {
            return Result.error("输错了 傻逼");
        }else {//令牌颁发
            Map map = new HashMap();
            map.put("empId",emp1.getId());
            map.put("username",emp1.getUsername());
            map.put("name",emp1.getName());
      //      map.put("password",emp1.getPassword());
            String jwtToken = JwtUtils.generateJwt(map);
        //最后令牌返回给data
            return Result.success(jwtToken);
        }
    }
}
